package com.scpii.universal.pns.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.doone.comm.paginaction.Pagination;
import com.scpii.universal.action.BaseAction;
import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.pns.entity.UserActions;
import com.scpii.universal.pns.service.UserActionsService;

@Controller
@Scope("prototype")
public class UserActionsManageAction extends BaseAction {

	private static final long serialVersionUID = 9126376965608530917L;
	@Resource
	private UserActionsService userActionsService;

	private Pagination page = new Pagination();

	private List<UserActions> userActions;

	private String userId;
	private String actionType;
	private Long targetId;

	public String getFavListInit() {
		actionType = "FAV";
		if (getSelectPerPage("page") == -1) {
			page.setPageRecord(10);
		} else {
			page.setPageRecord(getSelectPerPage("page"));
		}
		if (getQueryFlag("page") == -1) {

			page.setTotalRecord(userActionsService.getUserActionCountByType(
					getUserInfo().getAppId(), targetId, actionType));
		} else {
			page.setTotalRecord(getQueryFlag("page"));
		}
		setPageParameters(page, "page");
		userActions = userActionsService.getUserActionsByActionType(
				getUserInfo().getAppId(), targetId, actionType,
				page.getCurrentPage(), page.getPageRecord());

		return SUCCESS;
	}

	public String getOrderListInit() {
		actionType = "EC_ORDER_ADD";
		if (getSelectPerPage("page") == -1) {
			page.setPageRecord(10);
		} else {
			page.setPageRecord(getSelectPerPage("page"));
		}
		if (getQueryFlag("page") == -1) {

			page.setTotalRecord(userActionsService.getUserActionCountByType(
					getUserInfo().getAppId(), targetId, actionType));
		} else {
			page.setTotalRecord(getQueryFlag("page"));
		}
		setPageParameters(page, "page");
		userActions = userActionsService.getUserActionsByActionType(
				getUserInfo().getAppId(), targetId, actionType,
				page.getCurrentPage(), page.getPageRecord());
		return SUCCESS;
	}

	public UserActionsService getUserActionsService() {
		return userActionsService;
	}

	public void setUserActionsService(UserActionsService userActionsService) {
		this.userActionsService = userActionsService;
	}

	public Pagination getPage() {
		return page;
	}

	public void setPage(Pagination page) {
		this.page = page;
	}

	public List<UserActions> getUserActions() {
		return userActions;
	}

	public void setUserActions(List<UserActions> userActions) {
		this.userActions = userActions;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getActionType() {
		return actionType;
	}

	public void setActionType(String actionType) {
		if (actionType != null && !"".equals(actionType)) {
			String[] names = actionType.split(",");
			if (names != null && names.length > 0) {
				actionType = names[0];
			}
		}
		this.actionType = actionType;
	}

	public Long getTargetId() {
		return targetId;
	}

	public void setTargetId(Long targetId) {
		this.targetId = targetId;
	}

}
